<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>
import axios from 'axios';
import { caching, hussarAxiosRequestUtils, tenantUtils } from 'hussar-base';
import { LoginApi } from '@/api/loginApi';
export default {
  name: 'App',
  created() {
    this.getTenantType();
  },
  methods: {
    getTenantType() {
      hussarAxiosRequestUtils.getAction(LoginApi.getTenantConfig).then((res) => {
        if (res.code === 10000) {
          caching.local.set('tenantType', res.data.type);
          if (res.data.type && window.tenantType !== res.data.type) {
            console.warn('前后台的租户类型不匹配');
          }
        }
        this.getThemeColor();
      });
    },
    getThemeColor() {
      const config = this.setTenantHeader();
      const url = process.env.VUE_APP_HUSSAR_DEFAULT_API + '/themeConfig/getThemeColor';
      axios.get(url, config).then((res) => {
        if (res.data.code === 10000) {
          const data = res.data;// 主题色
          document.documentElement.style.setProperty('--theme-login-color', data.data.$themeColor);
        }
      });
    },
    setTenantHeader() {
      let config = {};
      if (window.tenantType === 'url') {
        const tcode = tenantUtils.getTCode();
        if (tcode) {
          config = {
            headers: {
              tcode
            }
          };
        }
        return config;
      } else if (window.tenantType === 'domain') {
        const domain = location.hostname;
        config = {
          headers: {
            domain
          }
        };
      }
      return config;
    }
  }
};
</script>
<style>
@import "~@/assets/font/font.css";
</style>
<style>
/*body{*/
/*  margin:0px;*/
/*  width:100%;*/
/*  min-width:1500px;*/
/*  max-width:100%;*/
/*  height:100%;*/
/*  background-color:#F0F0F0;*/
/*}*/
</style>
